import type { VbenFormSchema } from '#/adapter/form';
import type { VxeGridPropTypes } from '#/adapter/vxe-table';

import { $t } from '#/locales';

/** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] {
  return [
    {
      component: 'Input',
      fieldName: 'id',
      dependencies: {
        triggerFields: [''],
        show: () => false,
      },
    },
    {
      fieldName: 'name',
      label: $t('views.mp.account.name'),
      component: 'Input',
      rules: 'required',
      componentProps: {
        placeholder: $t('views.mp.account.namePlaceholder'),
      },
    },
    {
      fieldName: 'account',
      label: $t('views.mp.account.account'),
      component: 'Input',
      help: $t('views.mp.account.accountHelpMessage'),
      rules: 'required',
      componentProps: {
        placeholder: $t('views.mp.account.accountPlaceholder'),
      },
    },
    {
      fieldName: 'appId',
      label: $t('views.mp.account.appId'),
      component: 'Input',
      help: $t('views.mp.account.appIdHelpMessage'),
      rules: 'required',
      componentProps: {
        placeholder: $t('views.mp.account.appIdPlaceholder'),
      },
    },
    {
      fieldName: 'appSecret',
      label: $t('views.mp.account.appSecret'),
      component: 'Input',
      help: $t('views.mp.account.appSecretHelpMessage'),
      rules: 'required',
      componentProps: {
        placeholder: $t('views.mp.account.appSecretPlaceholder'),
      },
    },
    {
      fieldName: 'token',
      label: $t('views.mp.account.token'),
      component: 'Input',
      rules: 'required',
      componentProps: {
        placeholder: $t('views.mp.account.tokenPlaceholder'),
      },
    },
    {
      fieldName: 'aesKey',
      label: $t('views.mp.account.aesKey'),
      component: 'Input',
      componentProps: {
        placeholder: $t('views.mp.account.aesKeyPlaceholder'),
      },
    },
    {
      fieldName: 'remark',
      label: $t('common.remark'),
      component: 'Textarea',
      componentProps: {
        placeholder: $t('common.remarkPlaceholder'),
      },
    },
  ];
}

/** 搜索表单配置 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'name',
      label: $t('views.mp.account.name'),
      component: 'Input',
      componentProps: {
        placeholder: $t('views.mp.account.namePlaceholder'),
      },
    },
  ];
}

/** 表格列配置 */
export function useGridColumns(): VxeGridPropTypes.Columns {
  return [
    {
      title: $t('views.mp.account.name'),
      field: 'name',
    },
    {
      title: $t('views.mp.account.account'),
      field: 'account',
    },
    {
      title: $t('views.mp.account.appId'),
      field: 'appId',
    },
    {
      title: $t('views.mp.account.url'),
      field: 'url',
      slots: {
        default: ({ row }) => {
          return `http://server-url/admin-api/mp/open/${row.appId}`;
        },
      },
    },
    {
      title: $t('views.mp.account.qrCode'),
      field: 'qrCodeUrl',
      slots: {
        default: 'qrCodeUrl',
      },
    },
    {
      title: $t('common.remark'),
      field: 'remark',
    },
    {
      title: $t('common.action'),
      width: 260,
      fixed: 'right',
      slots: { default: 'actions' },
    },
  ];
}
